package com.iamteer.contact.service.impl;

import java.util.List;

import com.iamteer.contact.dao.ContactDao;
import com.iamteer.contact.dao.impl.ContactDaoImpl;
import com.iamteer.contact.entity.Contact;
import com.iamteer.contact.exception.NameDuplicatedException;
import com.iamteer.contact.service.ContactService;

public class ContactServiceImpl implements ContactService {
	ContactDao dao =  new ContactDaoImpl();
 	@Override
	public void addContact(Contact contact) throws NameDuplicatedException {
		if (dao.exists(contact.getName())) {
			//重复（出错）
			//返回自定义异常
			throw new NameDuplicatedException("姓名重复！");
		}else {
			dao.addContact(contact);
		}
	}

	@Override
	public void updateContact(Contact contact){
		dao.updateContact(contact);
	}

	@Override
	public void deleteContact(String id) {
		dao.deleteContact(id);
	}

	@Override
	public List<Contact> findAll() {
		return dao.findAll();
	}

	@Override
	public Contact findById(String id) {
		return dao.findById(id);
	}

}
